﻿using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using NLog.Extensions.Logging;
using SystemServices;

namespace LoggingDemo
{
    class Program
    {
        static void Main(string[] args)
        {

            ServiceCollection services = new ServiceCollection();
            services.AddLogging(logBuilder=> {
                //到底往哪里写通过这里配置,配置往文件就往文件写,配置往控制台写就往控制台写。这里可以配置多项,同时往控制台和文件写日志
                //logBuilder.AddConsole();
                logBuilder.AddNLog();
                //设置日志输出最低级别,如果不设置最低级别,默认最低级别为: LogLevel.Information,也就是不设置就不会输出Trace和Debug日志信息
                //logBuilder.SetMinimumLevel(LogLevel.Trace);
            });

            //注入
            services.AddScoped<Test1>();
            services.AddScoped<Test2>();


            using (var sp=services.BuildServiceProvider())
            {
                var test1 = sp.GetRequiredService<Test1>();
                var test2 = sp.GetRequiredService<Test2>();

                for (int i = 0; i < 10000; i++)
                {
                    test1.Test();
                    test2.Test();
                }
            }


            Console.ReadKey();
        }
    }
}
